package cn.wu.reggie.controller;

import cn.wu.reggie.common.R;
import cn.wu.reggie.entity.Orders;
import cn.wu.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("submit")
    public R save(@RequestBody Orders order, HttpSession session){
        // 1 给订单封装用户id
        Long userId = (Long) session.getAttribute("user");
        order.setUserId(userId);

        // 2 调用service完成保存操作
        return orderService.save(order);
    }

}
